var app = getApp();
Page(Object.assign({},{
    data:{
        datalist : [],
        inited : false,
        month : 0,
        t:0,
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onLoad:function(options){
        var self = this;
        var id = options.id ? options.id : ( options.scene ? options.scene : 0 );
        self.setData({
            options : options
        })
        app.com.auth(function(user){
            app.com.http('admin','POST',{op:'addtime',id:id},0,false,'','',function(res){
                if (!res.data.errno && res.data) {
                    self.setData({
                        Pagetheme : res.data.data.params.style,
                        shop : res.data.data.shop,
                        params : res.data.data.params,
                        shopbag : res.data.data.shopbag ? res.data.data.shopbag : false,
                    },function(){
                        self.setData({
                            inited : true,
                        });
                    });
                }else{
                    app.com.alert(res.data.message);
                }
            });
        });
        wx.setNavigationBarTitle({
          title:  '续期',
        });
    },
    onPullDownRefresh: function () {
        this.onLoad(this.data.options);
        wx.stopPullDownRefresh();
    },
    buyit(){
        var self = this;
        
        var postdata = {
            op : 'addtimepay',
            id : self.data.shop.id,
            month : self.data.month,
            t : self.data.t,
        };

        app.com.http('admin','POST',postdata,0,true,'','',function(res){
            if (!res.data.errno) {
                
                wx.requestPayment({
					'appId' : res.data.data.appId,
                    'timeStamp': res.data.data.timeStamp,
                    'nonceStr': res.data.data.nonceStr,
                    'package': res.data.data.package,
                    'signType': 'MD5',
                    'paySign': res.data.data.paySign,
                    'success': function (payres) {
                        if( payres.errMsg == 'requestPayment:ok' ){
                            app.com.toast('续费完成','success',function(){
                                wx.redirectTo({
                                    url : '/zofui_sales/admin/login'
                                });
                            });
                        }
                    },
                    'fail': function (payres) {
                        console.log(payres);
                    }
                });
                
            }else{
                app.com.alert(res.data.message);
            }
        });
    },
    chooseCard(e){
        this.setData({
            t : e.detail.value
        })
    },
    month(e){
        this.setData({
            month : e.detail.value
        })
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    FormIdsubmit : function(e){
        if( app.globalData.formarr.length <= 20 ) app.globalData.formarr.push(e.detail.formId);
    },
    
}))